package cm.tl.pms.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: wwh
 * @date: 2024/10/23 18:16
 */
public class TimeUtil {

    public static String getCurrentTime() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(new Date());
    }


    /**
     * 将给定的日期时间调整为当天的 23:59:59
     *
     * @param date 需要调整的日期时间
     * @return 调整后的日期时间
     */
    public static Date adjustToEOD(Date date) {
        if (date == null) {
            return null;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }


    public static void main(String[] args) {
        System.out.println("调整后的结束时间: " + TimeUtil.adjustToEOD(new Date()));
    }

}
